/**
 * 
 */
package com.jiang.service.impl;

import java.sql.Connection;
import java.util.List;
import com.jiang.dao.IProvinceDao;
import com.jiang.dao.impl.ProvinceDaoImpl;
import com.jiang.factory.DaoFactory;
import com.jiang.service.IAreaService;
import com.jiang.utils.DatabaseConnection;
import com.jiang.vo.Area;
import com.jiang.vo.AreaPlus;

/**
 * @author Administrator
 *
 */
public class AreaServiceImpl implements IAreaService {

	private Connection conn = null;
	private DatabaseConnection dbc = null;

	public AreaServiceImpl() {
		dbc = new DatabaseConnection();
		this.conn = dbc.getConnection();
	}

	@Override
	public List<Area> findAllArea() {
		List<Area> areas = null;
		try {
			// 如果是修改，并且牵扯到多张表的修改，就要采用手动提交，不用自动提交。并且做好事务回滚
			IProvinceDao provinceDao = DaoFactory.getInstance(this.conn, ProvinceDaoImpl.class);
			areas = provinceDao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.dbc.close();
		}
		return areas;
	}

	@Override
	public List<AreaPlus> findAllAreaPlusByAreaId(Integer areaId) {
		List<AreaPlus> areaPluses = null;
		try {
			IProvinceDao provinceDao = DaoFactory.getInstance(this.conn, ProvinceDaoImpl.class);
			areaPluses = provinceDao.findCitiesByAreaId(areaId);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.dbc.close();
		}
		return areaPluses;
	}
	

}
